package hongniang

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"shangyuapi/data_source"
	"shangyuapi/models"
	"time"
)

type JubaoBody struct {
	Hongniangid int64  `json:"hongniangid" gorm:"hongniangid"`
	Uid         int64  `json:"uid" gorm:"uid"`
	Title       string `json:"title" gorm:"title"`
	Images      string `json:"images" gorm:"images"`
	Addtime     int64  `json:"addtime" gorm:"addtime"`
	Cardzm      string `json:"cardzm" gorm:"cardzm"`
	Cardfm      string `json:"cardfm" gorm:"cardfm"`
	Cardsc      string `json:"cardsc" gorm:"cardsc"`
	Cailiao     string `json:"cailiao" gorm:"cailiao"`
	Phone       string `json:"phone" gorm:"phone"`
}

func Shensu(ctx *gin.Context) {
	request := JubaoBody{}
	ctx.ShouldBind(&request)
	hongniangid := request.Hongniangid
	cardzm := request.Cardzm
	cardfm := request.Cardfm
	cardsc := request.Cardsc
	cailiao := request.Cailiao
	phone := request.Phone
	title := request.Title
	jubao := models.Shensu{
		Hongniangid: hongniangid,
		Addtime:     time.Now().Unix(),
		Cardfm:      cardfm,
		Cardsc:      cardsc,
		Cardzm:      cardzm,
		Cailiao:     cailiao,
		Phone:       phone,
		Title:       title,
	}

	data_source.Db.Create(&jubao)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}

func Jubao(ctx *gin.Context) {
	request := JubaoBody{}
	ctx.ShouldBind(&request)
	hongniangid := request.Hongniangid
	uid := request.Uid
	title := request.Title
	images := request.Images
	jubao := models.Jubao{
		Uid:         uid,
		Hongniangid: hongniangid,
		Title:       title,
		Images:      images,
		Addtime:     time.Now().Unix(),
	}

	data_source.Db.Create(&jubao)

	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}
